let { projectRootPath } = require("../../../util/index");
let { getNewApp } = require(`${projectRootPath}/app/index.js`);
let { verifyToken } = require(`${projectRootPath}/util/jwt/index.js`);
let {
  uploadOwner,
  createOwner,
  getOwnerByPagination,
  editOwnerByUuid,
  removeOwnerByUuid,
  getOwnerByAll,
  getOwnerByPaginationAndQuestion,
} = require(`${projectRootPath}/service/owner/index.js`);
let { getTaskByPagination, editTaskByUuid, getTaskNotCompleteCount } = require(
  `${projectRootPath}/service/task/index.js`,
);
let { createPay, getPayByPagination } = require(
  `${projectRootPath}/service/pay/index.js`,
);
let {
  createNote,
  getNoteByPagination,
  getNoteNotCompleteCount,
  editNoteByUuid,
  removeNoteByUuid,
  getNoteByPaginationAndUuid,
} = require(`${projectRootPath}/service/note/index.js`);
let app = getNewApp();

// 创建备忘
app.post("/create", async (req, res) => {
  try {
    let result = await createNote(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});

// 获取备忘分页数据
app.post("/get/pagination", async (req, res) => {
  try {
    let result = await getNoteByPagination(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});

// 获取备忘分页数据通过 uuid
app.post("/get/paginationAndUuid", async (req, res) => {
  try {
    let result = await getNoteByPaginationAndUuid(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});

// 通过 uuid 获取全部未完成的备忘数量
app.post("/get/all/notCompleteCount", async (req, res) => {
  try {
    let result = await getNoteNotCompleteCount(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});

// 通过 uuid 编辑备忘
app.post("/edit/uuid", async (req, res) => {
  try {
    let result = await editNoteByUuid(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});

// 通过 uuid 编辑备忘
app.post("/remove/uuid", async (req, res) => {
  try {
    let result = await removeNoteByUuid(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});

// 导出 app
module.exports = app;
